import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
//引入封装好的模块
import menu from './modules/menu'
import manger from './modules/manger'
import role from './modules/role'
import cate from './modules/cate'
import specas from './modules/specas'
import shopmanger from './modules/shopmanger'
import member from './modules/member'
import banner from './modules/banner'
import seck from './modules/seck'

export default new Vuex.Store({
    state: {
        User: sessionStorage.getItem('userinfo') ? JSON.parse(sessionStorage.getItem('userinfo')) : null,
        name:'FT'
        
    },
    getters: {
        getUser(state) {
            return state.User
        }
    },
    mutations: {
        REQ_USER(state,payload){
         if(payload){
            state.User=payload
            sessionStorage.setItem('userinfo',JSON.stringify(payload))
         }else{
            sessionStorage.removeItem('userinfo')
         }
        }
    },
    actions: {
        //封装一个存储登录信息的行动
        changeUser({ commit }, payload) {
            console.log(payload,'传参');
            commit('REQ_USER', payload)
        }
    },
    modules: {
        menu,
        manger,
        role,
        cate,
        specas,
        shopmanger,
        member,
        banner,
        seck
    }
})